$(document).ready(function(){

		
	$.ajax({
  		type: "post",
 		url: "hmk/getWukuType_getWukuType.action",
  		success:function(data){
  			$.each(data.typeList,function(i,n){
  				$("<option value="+n.tpyeId+">"+n.tpyeName+"</option>").appendTo('#lawTypeID');
			});
  		}
	});
	
	$.ajax({
  		type: "post",
 		url: "hmk/getLawNature_findAll.action",
  		success:function(data){
  			$.each(data.lawNatureList,function(i,n){
  				$("<option value="+n.lnId+">"+n.lnName+"</option>").appendTo('#lawNatureID');
			});
  		}
	});

	getCurrent(1,10);
	
	$('#queryLaw').click(function(){		
		var page=1;
		var maxRow=10;
		getCurrent(page,maxRow);
	});
	
	$('#firstPage').click(function(){		
		var page=1;
		var maxRow=$("#maxRow").text();
		getCurrent(page,maxRow);
	});
	
	$('#prePage').click(function(){		
		var page=$("#page").text();
		page=(parseInt(page)-1);
		var maxRow=$("#maxRow").text();
		if(page<=0){
			alert("第一页了");
			return ;
		}
		getCurrent(page,maxRow);
	});
	
	$('#nextPage').click(function(){		
		var page=$("#page").text();
		page=(parseInt(page)+1);
		var maxRow=$("#maxRow").text();
		var pageCount=$("#pageCount").text();
		if(page>=pageCount){
			alert("最后一页了");
			return;
		}
		getCurrent(page,maxRow);
	});
	
	$('#lastPage').click(function(){		
		var page=$("#pageCount").text();
		var maxRow=$("#maxRow").text();
		getCurrent(page,maxRow);
	});
	
	$('#jumpPage').click(function(){		
		var pageCount=$("#pageCount").text();
		var maxRow=$("#maxRow").text();
		var page=$("#jump").val();
		if(page>pageCount){
			alert("页数过大");
			return;
		}
		getCurrent(page,maxRow);
	});

	
});

	function getCurrent(page1,maxRow1){
		var page=page1;
		var maxRow=maxRow1;
		
		var typeID=$('#lawTypeID option:selected').val();
		var lawNatureID=$('#lawNatureID option:selected').val();
		var lawName=$('#top_lawNameID').val();
		
		$('#lawBody').empty();	
		$("#loadingPerson").show();
		$.ajax({
  			type: "post",
 			url: "hmk/findSomeLaw_findLawList.action",
 			data:{
 				  typeID1:typeID,lawNature1:lawNatureID,lawName1:lawName,lawDetail1:"",
 				  page:page,maxRow:maxRow
 				 },
  			success:showData
		 });	
		 
	}

	function getLawDetail(v){
		var content = $(v).next().text();
		window.location.href="/ag/hmk/findOneLaw_findOneLaw.action?lawID1="+content +"&findType1=2";
	}
	
	
	function showData(data){
		$('#lawBody').empty();	
		if(data.pageUtil.list.length==0){
			$("#loadingPerson").hide();
			$("#nonePerson").show();
			$("#total").text(0);
			$("#page").text(0);
			$("#pageCount").text(0);
			$("#maxRow").text(0);
		}else{
		
		   $("#nonePerson").hide();
		    $("#loadingPerson").hide();
		    $.each(data.pageUtil.list,function(i,n){
				fillDataToHtml(n.lawId,n.tbType.tpyeName,n.tbLawnature.lnName,
							   n.lawName,n.lawDetail,data.lawKeywordList[i],n.lawFjRote);
						  
		  	});
		
		$('#total').text(data.pageUtil.total);
		$('#page').text(data.pageUtil.page);
		$('#pageCount').text(Math.ceil(data.pageUtil.total/10));
		$('#maxRow').text(data.pageUtil.maxRow);
		}
	}
	
	function fillDataToHtml(lid,ltype,lnature,lname,ldetail,lkeyword,lfjname){
		var strHtml="<tr>";
		strHtml+="<td height='30px' bgcolor='#FFFFFF'><div align='center' class='STYLE2 STYLE1'>";
        strHtml+=ltype+"</div></td>";
        strHtml+="<td height='30px' bgcolor='#FFFFFF'><div align='center' class='STYLE2 STYLE1'>";
        strHtml+=lnature+"</div></td>";
        strHtml+="<td height='30px' bgcolor='#FFFFFF'><div align='center' class='STYLE2 STYLE1'>";
        strHtml+=lname+"</div></td>";
        strHtml+="<td height='30px' bgcolor='#FFFFFF'><div align='center' class='STYLE2 STYLE1'>";
        strHtml+=ldetail+"</div></td>";
        strHtml+="<td height='30px' bgcolor='#FFFFFF'><div align='center' class='STYLE2 STYLE1'>";
        strHtml+=lkeyword+"</div></td>";
        strHtml+="<td height='30px' bgcolor='#FFFFFF'><div align='center' class='STYLE2 STYLE1'>";
        strHtml+=lfjname+"</div></td>";
       
        strHtml+="<td height='30px' bgcolor='#FFFFFF'><div align='center'><img src='hmk/images/037.gif' width='9' height='9' /><span class='STYLE1'> [</span><a style='cursor:pointer' onclick='getLawDetail(this)'>详情</a>";
			strHtml+="<span id='cID' style='display:none'>";
	    	strHtml+=lid;
	    	strHtml+="</span>";        
        strHtml+="<span class='STYLE1'>]</span></div></td>";
        strHtml+="</tr>";
        
        $('#lawBody').append(strHtml);
	}